//地图功能
//接受地图的id名 解析地址的名称 接受纬度的id名 接受经度的id名
function initialize_markerMap(map_name,address="",lat_name,lng_name) {
    var geocoder = new google.maps.Geocoder();
    var map_marker=new google.maps.Marker();
    var map_id;
    var myOptions = {
        zoom : 10,//缩放比例
        center:new google.maps.LatLng(39.90419989999999,116.40739630000007),//北京
        mapTypeId : google.maps.MapTypeId.ROADMAP
    }
    map_id = new google.maps.Map(document.getElementById(map_name),
        myOptions);
    map_marker.setMap(null);
    map_marker = new google.maps.Marker({
        map : map_id,
        position :new google.maps.LatLng(39.90419989999999, 116.40739630000007),
        //坐标动画效果
        animation : google.maps.Animation.DROP
    });
    map_marker.setMap(map_id);
    if(address!="" && address != null && address != undefined ){
        return codeAddress(map_name,address,lat_name,lng_name);
    }else{
        return [];
    }
}

function codeAddress(map_name,address,lat_name,lng_name) {
    var geocoder = new google.maps.Geocoder();
    var map_marker=new google.maps.Marker();
    var map_id;
    var myOptions = {
        zoom : 10,//缩放比例
        center:new google.maps.LatLng(39.90419989999999,116.40739630000007),//北京
        mapTypeId : google.maps.MapTypeId.ROADMAP
    }
    map_id = new google.maps.Map(document.getElementById(map_name),
        myOptions);
    map_marker.setMap(null);
    //地址解析
    geocoder.geocode({
        'address' : address
    }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            //依据解析的经度纬度设置坐标居中
            map_id.setCenter(results[0].geometry.location);
            map_marker = new google.maps.Marker({
                map : map_id,
                position : results[0].geometry.location,
                title : address,
                //坐标动画效果
                animation : google.maps.Animation.DROP
            });
            map_marker.setMap(map_id);
            $("input[name=lat]").val(results[0].geometry.location.lat);
            $("input[name=lng]").val(results[0].geometry.location.lng);
            $("input[name=place_id]").val(results[0].place_id);
        }
    });
}

function SearchAddress(address,addressbox) {
    var geocoder = new google.maps.Geocoder();
    //地址解析
    geocoder.geocode({
        'address' : address
    }, function(results, status) {
        addressbox.children().remove();
        if (status == google.maps.GeocoderStatus.OK) {
            var html = '';
            for(var i in results){
                html+="<span>"+results[i].formatted_address+"</span>";
            }
            addressbox.html(html);
        }
    });
}